package normalCilent;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.Map;

/*
* tcp客户端类
 */
public class Client {
    public static void main(String[] args) {
        try {
            // 创建客户端Socket，指定服务器地址和端口
            Socket socket = new Socket("127.0.0.1", 5000);

            String userInfo = "admin,admin";

            HashSet<String> hashSet=new HashSet<>();
            hashSet.add("wdnmd");
            hashSet.add("zzq");
            hashSet.add("fku");

            // 获取输出流，向服务器端发送信息
            OutputStream outputStream = socket.getOutputStream();// 字节输出流
            ObjectOutputStream objectOutputStream=new ObjectOutputStream(outputStream);
            objectOutputStream.writeObject(hashSet);
//            PrintWriter pw = new PrintWriter(outputStream);// 将输出流包装成打印流
//            pw.write(userInfo);
//            pw.flush();
            socket.shutdownOutput();

            // 获取输入流，并读取服务器端的响应信息
            InputStream inputStream = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String info = null;
            while ((info = br.readLine()) != null) {
                System.out.println("receive:" + info);
            }

            // 4、关闭资源
            br.close();
            inputStream.close();
//            pw.close();
            outputStream.close();
            socket.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
